<?php
require '../script/mysqlconfig.php';
/* 连接数据库*/
$mysqli = new mysqli(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_NAME);
if($mysqli->connect_error){
    die("数据库连接错误：". $mysqli->connect_error);
}
//$pass_hash=password_hash($_POST["pass"],PASSWORD_DEFAULT);
$name = $_POST["name"];
/* 判断用户是否点击了登录按钮*/
if(isset($_POST["login"])){
    $sql = "SELECT password FROM users WHERE name='$name'";
    $res =$mysqli->query($sql)->fetch_assoc();
    /**登录验证 */
    if($res){
        if(password_verify($_POST["pass"],$res["password"])){
            echo "<script>alert('登录成功！') ;window.location.href='../index.php';</script>";
        }else{
            echo "<script>alert('密码错误!');history.go(-1);</script>";
        }
    }else{
        echo "<script>alert('用户不存在!');history.go(-1);</script>";
    }
}

